package everydayGrade.t4;

import org.junit.jupiter.api.Test;
import tool.s;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-11-18-13:42
 * @Description: 1.0
 */
public class T2342 {
    public int maximumSum(int[] nums) {
        Arrays.sort(nums);
        s.print(nums);
        int n = nums.length,maxSum=-1;
        int[] hasNum = new int[82];
        Arrays.fill(hasNum, -1);
        for (int i = n - 1; i >= 0; i--) {
            int sum = getGibberishTotal(nums[i]);
            System.out.println(nums[i]+" "+sum);
            if (hasNum[sum] == -1) {
                hasNum[sum] = nums[i];
            }else{
                maxSum=Math.max(maxSum,nums[i] + hasNum[sum]);
                if (nums[n-1]+nums[i]<=maxSum){
                    return maxSum;
                }
            }
        }
        return maxSum;
    }

    public int getGibberishTotal(int num) {
        int sum = 0;
        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
        return sum;
    }
    @Test
    public void test() {
        System.out.println(maximumSum(new int[]{368,369,307,304,384,138,90,279,35,396,114,328,251,364,300,191,438,467,183}));
    }

}
